package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.union.parergon.UnionParergonOperateResult;
import com.yanqu.road.entity.union.parergon.UnionParergonPlayer;
import com.yanqu.road.pb.union.Parergon;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.server.manager.union.CrossUnionParergonMgr;
import com.yanqu.road.server.manager.union.CrossUnionReqContext;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_UNION_PARERGON_OPERATE, desc = "点击经营")
public class CrossOperateCmd extends CrossCommand {

    long playerId;

    UnionParergonOperateResult result = new UnionParergonOperateResult();

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        playerId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        Parergon.OperateReqMsg reqMsg = Parergon.OperateReqMsg.parseFrom(packet.getBytes());
        int parergonId = reqMsg.getParergonId();
        int type = reqMsg.getType();
        int operateTimes = reqMsg.getOperateTimes();

        result = CrossUnionMgr.parergonOperate(serverId, playerId, parergonId, type, operateTimes);
    }

    @Override
    public void sendData() {
        if(result.getRet() != 0){
            Parergon.OperateRespMsg.Builder respMsg = CrossUnionParergonMgr.builderOperateRespMsg(result);
            MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(Protocol.U_UNION_PARERGON_OPERATE, respMsg));
        }
    }
}
